<?php
class AccountController extends Zgm_Controller_Base
{

    public function init()
    {
        /* Initialize action controller here */
    }
    //show user data
    public function indexAction(){

    if (Model_Users::isLogged()) {
    $identity = Zend_Auth::getInstance()->getIdentity();
    if ((isset($identity))&&(!empty($identity))) {
        $id = $identity['id'];
        $userModel = new Model_Users();
        $userData = $userModel->getByUserId($id);
        $this->view->profileData = $userData;
     }
   }
}

    public function editAction(){

    if (Model_Users::isLogged()) {
    $identity = Zend_Auth::getInstance()->getIdentity();

    if ((isset($identity))&&(!empty($identity))) {
        // Gather data for distance statistics.
        $statistics = array(
            'total' => 1,
            'avg'   => 2,
        );
        $this->view->statistics = $statistics;

        $id = $identity['id'];
        $userModel = new Model_Users();
        $userData = $userModel->getByUserId($id);
        $form = new Form_Account($identity['email']);
        $this->view->form = $form;
        $form->populate($userData);

        //when submit
        if ($this->_request->isPost()) {
            if ($form->isValid($this->_request->getPost())) {
                $args = array();
                $args = $form->getValues();
                $args['id'] = $identity['id'];
                $userModel = new Model_Users();
                $saveUserDataResult = $userModel->save($args);
                Zend_Auth::getInstance()->getStorage()->write(array('id' => $identity['id'],
                                                                    'role_id' => $args['privacy'],
                                                                    'email' => $args['email']));
            } else {
               syslog(LOG_WARNING, 'The form data is invalid with error messages. '.$form->getMessages());
            }
        }
    }
    } else { echo 'you are not logged!';}

}
}